package com.open.demo.api;

import com.kymjs.rxvolley.client.HttpCallback;

import java.util.HashMap;

/**
 * 当呗API封装.
 */
public class DangBeiApi {

    public static final String ROOT_ADDR = "http://api.znds.com/openapi/";

    public static final String CLASS_ADDR = ROOT_ADDR + "list.php"; // 分类
    public static final String SPECIAL_COLLECTION_ADDR = ROOT_ADDR + "tjlist.php"; // 专题合集
    public static final String HOT_LIST_ADDR = ROOT_ADDR + "hot.php"; // 排行榜
    public static final String DETAILS_PAGE_ADDR = ROOT_ADDR + "view.php"; // 详情页面.
    public static final String HOME_RECOMMENDED_ADDR = ROOT_ADDR + "tjnew.php"; // 首页推荐

    public static final String SEARCH_APP_ADDR =ROOT_ADDR + "sou.php"; // 搜索应用.
    public static final String SEARCH_PACK_NAME_ADDR =ROOT_ADDR + "soupack.php"; // 根据包名搜索.
    public static final String ALL_APP_ADDR = ROOT_ADDR + "allapp.php"; // 获取全部应用.
    public static final String STYLE_ADDR = ROOT_ADDR + "style.php"; // 获取皮肤图片.
    public static final String CHECK_APP_UPDATE_ADDR = ROOT_ADDR + "acheck.php"; // 检查应用更新

    /**
     * 获取分类.
     *
     * @param modid 分类ID详情参考-当呗API文档-2.3
     * @param page  当前页数
     * @param cb    回调
     */
    public void getClassInfo(int modid, int page, final HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("modid", modid);
        params.put("page", page);
        HttpRequstHelp.getInstance().get(CLASS_ADDR, params, cb);
    }

    /**
     * 获取专辑集合
     *
     * @param id   分类ID详情参考-当呗API文档-3.3
     * @param page 当前页数
     * @param cb   回调
     */
    public void getSpecialCollection(int id, int page, HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        params.put("page", page);
        HttpRequstHelp.getInstance().get(SPECIAL_COLLECTION_ADDR, params, cb);
    }

    /**
     * 获取排行榜
     *
     * @param modid 分类ID详情参考-当呗API文档-4.3
     * @param page  page 当前页数
     * @param cb    回调
     */
    public void getHotList(int modid, int page, HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("modid", modid);
        params.put("page", page);
        HttpRequstHelp.getInstance().get(HOT_LIST_ADDR, params, cb);
    }

    /**
     * 获取详细页面
     *
     * @param id 应用ID标识，列表页返回的appid.
     * @param cb 回调
     */
    public void getDetailsPage(int id, HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        HttpRequstHelp.getInstance().get(DETAILS_PAGE_ADDR, params, cb);
    }

    /**
     * 获取主页推荐
     *
     * @param cb
     */
    public void getHomeRecommended(HttpCallBack cb) {
        HttpRequstHelp.getInstance().get(HOME_RECOMMENDED_ADDR, cb);
    }

    /**
     * 获取推荐应用.
     *
     * @param cb
     */
    public void getRecommendedApp(HttpCallBack cb) {
        getSpecialCollection(5, 1, cb);
    }

    /**
     * 获取推荐游戏.
     *
     * @param cb
     */
    public void getRecommendedGame(HttpCallBack cb) {
        getSpecialCollection(6, 1, cb);
    }

    /**
     * 根据字符串-搜索
     *
     * @param keyword 搜索关键字
     * @param page    当前页数
     * @param cb      回调
     */
    public void searchApp(String keyword, int page, HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("kw", keyword);
        params.put("Page", page);
        HttpRequstHelp.getInstance().get(SEARCH_APP_ADDR, params, cb);
    }

    /**
     * 根据包名-搜索.
     *
     * @param packName 搜索关键字-包名(cm.open...)
     * @param page     当前页数
     * @param cb       回调
     */
    public void searchPack(String packName, int page, HttpCallBack cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("kw", packName);
        params.put("Page", page);
        HttpRequstHelp.getInstance().get(SEARCH_PACK_NAME_ADDR, params, cb);
    }

    /**
     * 获取全部应用.
     *
     * @param cb
     */
    public void getAllApp(HttpCallBack cb) {
        HttpRequstHelp.getInstance().get(ALL_APP_ADDR, cb);
    }

    /**
     * 获取皮肤图片.
     *
     * @param cb
     */
    public void getStyle(HttpCallBack cb) {
        HttpRequstHelp.getInstance().get(STYLE_ADDR, cb);
    }

    /**
     * 检查应用更新接口. (post)
     *
     * @param packs APP包名,格式为(com,open,****)，包名用半角逗号分隔
     * @param cb    回调
     */
    public void checkAppUpdate(String packs, HttpCallback cb) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("packs", packs);
        HttpRequstHelp.getInstance().post(CHECK_APP_UPDATE_ADDR, params, cb);
    }

}
